<template>
    <div>
        <van-nav-bar
                :fixed="fixed"
                title="转出"
                left-text="返回"
                right-text="余额记录"
                left-arrow
                @click-left="onClickLeft"
                @click-right="onClickRight"
        />
        <form @submit.prevent="setData" :style="{marginTop:'46px'}">
            <van-cell-group>
                    <van-field
                            v-model="username"
                            label="转出ID"
                            placeholder="请输入要转的用户ID"
                    />
                <van-field
                        v-model="amount"
                        label="转出金额"
                        placeholder="请输入要转的金额"
                />
                <van-field
                        v-model="remarks "
                        label="转账备注"
                        placeholder="请输入转账备注"
                />
            </van-cell-group>
        </form>
        <div :style="{colon: '#ffffff',padding:'10px'}">
            <van-button size="large" :style="{marginTop: '10px'}" @click="setData">确定</van-button>
        </div>
    </div>
</template>

<script>
    import {BalanceTransfer} from "../api/data";
    import Vue from 'vue'
    import { Toast } from 'vant';
    Vue.use(Toast);
    export default {
        data(){
            return{
                fixed:true,
                username:'',
                amount:'',
                remarks:''
            }
        },
        computed:{
            token:function () {
                return ""
            }
        },
        methods:{
            setData(){
                console.log(this.username)
                if (this.username=='') {
                    Toast('请输入正确的ID！')
                    return
                }
                if (this.amount=='') {
                    Toast('请输入正确的转金额！')
                    return
                }
                if (this.remarks=='') {
                    Toast('请输入转账备注！')
                    return
                }
                BalanceTransfer(this.username,this.amount,this.remarks,this.token).then(res=>{
                    console.log(res.data)
                    if (res.data.code == '10001') {
                        Toast('登录已失效，请重新登录！')
                        this.$router.push({path:`/login`})
                        return
                    }
                    if (res.data.msg == '收款人不存在！') {
                        Toast('收款用户不存在！')
                        return
                    }
                    if (res.data.msg == '余额不足') {
                        Toast('账户余额不足！')
                        return
                    }
                    if (res.data.msg == '转账成功！') {
                        Toast('转账成功！')
                        return
                    }
                })
            },
            onClickLeft() {
                this.$router.back()
            },
            onClickRight(){
                this.$router.push({
                    path:`/balance`
                })
            }
        },
        created(){
            this.username = this.$route.query.user_id
        }
    }
</script>
<style>
    . .van-cell__title{
        padding-top: 10px;
    }
</style>
<style scoped>

</style>
